import { getData } from '@vimi/utils-api'

export default {
  methods: {
    save(data) {
      return this.$api.addData(this.$serviceName, 'gua_contract', data)
    },
    deleteData(id) {
      return this.$api.deleteData(this.$serviceName, 'gua_contract', id)
    },
  },
}

// 从委托合同中获取放款金额
export const getEntrustContract = async relatedList => {
  if (!relatedList.length) return
  const res = await getData({
    table: 'entrust_contract',
    params: {
      'customer_related_id.in': relatedList.map(it => it.customer_related_id).join(','),
      fields: ['customer_related_id', 'reply_funds', 'bank_name'],
    },
  })
  return (res?.data ?? []).reduce((prev, curr) => {
    prev[curr.customer_related_id] = curr || {}
    return prev
  }, {})
}
